package com.ssmTest.controller;

import com.google.gson.Gson;
import com.ssmTest.model.*;
import com.ssmTest.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MobileADController {
    @Autowired
    private IUserService iUserService;

    @Autowired
    private DateTimeService dateTimeService;
    @Autowired
    private IEmploymentAdService iEmploymentAdService;
    @Autowired
    private IInterviewsService iInterviewsService;
    @Autowired
    private IJobAdService iJobAdService;

    //企业-------------------------------------------------------------------


    //发布招聘信息
    @RequestMapping(value = "/releaseEmploymentAD.do")
    @ResponseBody
    public Result releaseEmploymentAD(@RequestParam("json") String json) {
        // 1成功
        Gson gson = new Gson();
        EmploymentAd employmentAd = gson.fromJson(json, EmploymentAd.class);
        Result result = new Result();
        employmentAd.setTime(dateTimeService.getTime());
        iEmploymentAdService.insertEmploymentAd(employmentAd);
        result.setCode(1);
        return result;
    }


    //查询招聘信息列表
    @RequestMapping(value = "/getEmploymentAD.do")
    @ResponseBody
    public Result getEmploymentAD(@RequestParam("pagenum") int pagenum, @RequestParam("city") String city, @RequestParam("key") String key) {
        //0列表为空  1生成信息列表
        Result result = new Result();
        List<EmploymentAd> list = null;
        if (!key.equals(""))
            list = iEmploymentAdService.selectSecondByAndKey(pagenum, city, key);
        else
            list = iEmploymentAdService.selectSecondByNoKey(pagenum, city);
        if (list.size() == 0)
            result.setCode(0);
        else {
            result.setCode(1);
            result.setData(list);
        }
        return result;
    }

    //招聘信息报名
    @RequestMapping(value = "/interviewSignUp.do")
    @ResponseBody
    public Result interviewSignUp(@RequestParam("json") String json) {
        // 1成功
        return iInterviewsService.preseInterview(json);
    }


    //个人-------------------------------------------------------------------
    //发布个人求职
    @RequestMapping(value = "/releaseJobAD.do")
    @ResponseBody
    public Result releaseJobAD(@RequestParam("json") String json) {
        // 1成功
        Gson gson = new Gson();
        JobAd jobAd = gson.fromJson(json, JobAd.class);
        Result result = new Result();
        jobAd.setTime(dateTimeService.getTime());
        iJobAdService.insertJobAd(jobAd);
        result.setCode(1);
        return result;
    }

    //查询个人求职列表
    @RequestMapping(value = "/getJobAD.do")
    @ResponseBody
    public Result getJobAD(@RequestParam("pagenum") int pagenum, @RequestParam("city") String city, @RequestParam("key") String key) {
        //0列表为空  1生成信息列表
        Result result = new Result();
        List<JobAd> list = null;
        if (!key.equals(""))
            list = iJobAdService.selectJobAdByAndKey(pagenum, city, key);
        else
            list = iJobAdService.selectJobAdByNoKey(pagenum, city);
        if (list.size() == 0)
            result.setCode(0);
        else {
            result.setCode(1);
            result.setData(list);
        }
        return result;
    }

    //企业点击面试
    //企业点击面试之后形成一个Interviews，其中电话号码字段为双方的电话  公司电话,个人电话  中间用","间隔开，其他字段照常
    @RequestMapping(value = "/interviewBus.do")
    @ResponseBody
    public Result interviewBus(@RequestParam("json") String json) {
        // 1成功
        return iInterviewsService.preseInterview(json);
    }
}
